package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usian.apis.wemedia.WemediaControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.impl.WemediaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WemediaController implements WemediaControllerApi {
    @Autowired
    private WemediaServiceImpl wemediaService;

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        wemediaService.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }

    @Override
    @PostMapping("findByName{name}")
    public WmUser findByName(@PathVariable String name) {
        return wemediaService.getOne(new QueryWrapper<WmUser>().lambda().like(WmUser::getName, name));

    }
    @PostMapping("updateAuthor")
    public ResponseResult updateAuthor(@RequestBody WmUser wmUser) {
       wemediaService.updateById(wmUser);
       return wemediaService.Success;
    }
}
